package com.imddy.tweb.task.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.TriggerKey;

public class HelloJob implements Job{
	

	/**
	 * HelloJob的任务
	 * 打执行时候和helloworld
	 */
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println("Current Exec Time is: " + simpleDateFormat.format(date));
		System.out.println("Helloworld!");
		
		// get jobExecutionContext
		JobKey jobKey = context.getJobDetail().getKey();
		TriggerKey triggerKey = context.getTrigger().getKey();
		JobDetail jobDetail = context.getJobDetail();
		
		System.out.println("My Job Name and Group: " + jobKey.getName() + " : " + jobKey.getGroup() );
		System.out.println("My Trigger Name and Group: " + triggerKey.getName() + " : " + triggerKey.getGroup() );
		System.out.println("job Class: " + jobDetail.getJobClass().getName());
		
		JobDataMap jDataMap = context.getJobDetail().getJobDataMap();
		JobDataMap tDataMap = context.getTrigger().getJobDataMap();
		JobDataMap dataMap = context.getMergedJobDataMap();
		
		System.out.println(jDataMap.size() + " : " + tDataMap.size() + " : " + dataMap.size());
		for (Object object : jDataMap.values()) {
			System.out.println("job jobdatamap: " + object);
		}
		for (Object object : tDataMap.values()) {
			System.out.println("trigger jobdatamap: " + object);
		}
		for (Object object : dataMap.values()) {
			System.out.println("mergeddatamap: " + object);
		}
		
		
		
	}

}
